//
//  Interface.m
//  SportSocial
//
//  Created by yull on 14/11/19.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "Interface.h"

@implementation Interface

+ (RESideMenu *)createSideMenu
{
    UITabBarController *centerController = [self createMainTabbarController];
    
    UIViewController *leftController = [self createLeftViewController];
    
    RESideMenu *sideMenu = [[RESideMenu alloc] initWithContentViewController:centerController leftMenuViewController:leftController rightMenuViewController:nil];
    sideMenu.contentViewInPortraitOffsetCenterX = 0.0f;
    sideMenu.contentViewScaleValue = 0.7f;
    sideMenu.bouncesHorizontally = NO;
    
    return sideMenu;
}

+ (UITabBarController *)createMainTabbarController
{
    UITabBarController *tabbarController = [[UITabBarController alloc] init];
    
    RecentListVIewController *recentViewController = [[RecentListVIewController alloc] init];
    NewsViewController *newsViewController = [[NewsViewController alloc] init];
    NearRootViewController *nearViewController = [[NearRootViewController alloc] init];
    
    UINavigationController *recentNavi = [[UINavigationController alloc] initWithRootViewController:recentViewController];
    
    UINavigationController *newsNavi = [[UINavigationController alloc] initWithRootViewController:newsViewController];
    UINavigationController *nearNavi = [[UINavigationController alloc] initWithRootViewController:nearViewController];
    
    tabbarController.viewControllers = [NSArray arrayWithObjects:recentNavi,newsNavi,nearNavi, nil];
    
    recentNavi.tabBarItem = [self createWithTitle:@"消息" normalImage:[UIImage imageNamed:@"tedbar_message_normal"] selectImage:[UIImage imageNamed:@"tedbar_message_selected"]];
    
    newsNavi.tabBarItem = [self createWithTitle:@"新闻" normalImage:[UIImage imageNamed:@"tedbar_news_normal"] selectImage:[UIImage imageNamed:@"tedbar_news_selected"]];
    
    nearNavi.tabBarItem = [self createWithTitle:@"附近" normalImage:[UIImage imageNamed:@"tedbar_near_normal"] selectImage:[UIImage imageNamed:@"tedbar_near_selected"]];
    
    tabbarController.tabBar.barTintColor = [UIColor whiteColor];
    
    NSDictionary *dict = @{NSForegroundColorAttributeName:[UIColor whiteColor],
                           NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f]};
    [[UINavigationBar appearance] setTitleTextAttributes:dict];
    
    recentViewController.view.frame = recentViewController.view.frame;
    tabbarController.selectedIndex = 1;
    
    return tabbarController;
}

+ (LeftSideViewController *)createLeftViewController
{
    return [[LeftSideViewController alloc] init];
}

+ (UIViewController *)createLoginViewController
{
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    loginViewController.hidesBottomBarWhenPushed = YES;
    return loginViewController;
}

+ (UIViewController *)createRegistViewController
{
    UIViewController *registViewController = [[RegistViewController alloc] init];
    registViewController.hidesBottomBarWhenPushed = YES;
    return registViewController;
}

+ (UIViewController *)createMyInfoViewController
{
    UIViewController *myInfoViewController = [[MyInfoViewController alloc] init];
    myInfoViewController.hidesBottomBarWhenPushed = YES;
    return myInfoViewController;
}

+ (UIViewController *)createFriendViewController
{
    UIViewController *friendViewController = [[FriendViewController alloc] init];
    friendViewController.hidesBottomBarWhenPushed = YES;
    return friendViewController;
}

+ (UIViewController *)createNoticeViewController
{
    UIViewController *noticeViewController = [[NoticeViewController alloc] init];
    noticeViewController.hidesBottomBarWhenPushed = YES;
    return noticeViewController;
}

+ (UIViewController *)createPhotoViewController
{
    UIViewController *photoViewController = [[PhotoViewController alloc] init];
    photoViewController.hidesBottomBarWhenPushed = YES;
    return photoViewController;
}

+ (UIViewController *)createSportPlanViewController
{
    UIViewController *sportPlanViewController = [[SportPlanViewController alloc] init];
    sportPlanViewController.hidesBottomBarWhenPushed = YES;
    return sportPlanViewController;
}

+ (UIViewController *)createGroupListViewController
{
    UIViewController *groupListViewController = [[GroupListViewController alloc] init];
    groupListViewController.hidesBottomBarWhenPushed = YES;
    return groupListViewController;
}

+ (UIViewController *)createSettingViewController
{
    UIViewController *settingViewController = [[SettingViewController alloc] init];
    settingViewController.hidesBottomBarWhenPushed = YES;
    return settingViewController;
}

#pragma mark - private
+ (UITabBarItem *)createWithTitle:(NSString *)title
                      normalImage:(UIImage *)normalImage
                      selectImage:(UIImage *)selectImage
{
    normalImage = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:normalImage selectedImage:selectImage];
    NSDictionary *normalDict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, [UIFont systemFontOfSize:14.0f],NSFontAttributeName, nil];
    
    NSDictionary *selectDict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, [UIFont systemFontOfSize:14.0f],NSFontAttributeName, nil];
    
    [item setTitleTextAttributes:normalDict forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectDict forState:UIControlStateSelected];
    
    item.titlePositionAdjustment = UIOffsetMake(0, -3);
    item.imageInsets = UIEdgeInsetsMake(-3, 0, 3, 0);
    return item;
}

+ (UIViewController *)createUserInfoViewControllerWithUserId:(UInt64)userId userName:(NSString *)userName
{
    UIViewController *friendInfo = [[UserInfoViewController alloc] initWithUserId:userId userName:userName];
    friendInfo.hidesBottomBarWhenPushed = YES;
    return friendInfo;
}

+ (UIViewController *)createGroupInfoWithNearGroup:(NearGroup *)nearGroup
{
    UIViewController *groupInfo = [[GroupInfoViewController alloc] initWithNearGroup:nearGroup];
    return groupInfo;
}

+ (UIViewController *)createNewsContentWithNews:(NewsModel *)news
{
    UIViewController *newsContent = [[NewsContentViewController alloc] initWithNews:news];
    return newsContent;
}
@end
